package com.ys.erp.entity.data.bean;

import com.baomidou.mybatisplus.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

/**
 * @author lwj
 * @date 2025/9/18
 */

@Data
@TableName(value = "t_user_contract")
public class UserContract {
    /**
     * 主键id
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 用户编号
     */
    @TableField(value = "user_id")
    private Long userId;

    @TableField(value = "user_name")
    private String userName;

    @TableField(value = "user_phone")
    private String userPhone;

    @TableField(value = "user_id_card")
    private String userIdCard;

    /**
     * 宠物编号
     */
    @TableField(value = "pet_code")
    private String petCode;

    /**
     * 来源，SIGN:线上签约
     */
    @TableField(value = "source_type")
    private String sourceType;

    /**
     * 来源编号
     */
    @TableField(value = "source_no")
    private String sourceNo;

    /**
     * 来源描述
     */
    @TableField(value = "source_des")
    private String sourceDes;

    /**
     * 签署合同类型，
     * TAKE_PET_CONTRACT：领猫合同
     * USER_KNOW_CONTRACT：用户须知合同
     * RESERVE_CONTRACT:预定合同
     * BUY_CONTRACT:直购合同
     */
    @TableField(value = "`type`")
    private String type;

    /**
     * 合同名称
     */
    @TableField(value = "`name`")
    private String name;

    /**
     * 合同编号
     */
    @TableField(value = "`number`")
    private String number;

    /**
     * 店铺代码
     */
    @TableField(value = "shop_code")
    private String shopCode;

    /**
     * 导购人员id
     */
    @TableField(value = "guide_id")
    private Long guideId;

    /**
     * 签约编号
     */
    @TableField(value = "apply_no")
    private String applyNo;

    /**
     * 签署状态 init:待签，SIGN_ING:签约中，SUCCESS:成功，ABANDON:废弃
     */
    @TableField(value = "contract_status")
    private String contractStatus;

    /**
     * 合同链接
     */
    @TableField(value = "contracts_url")
    private String contractsUrl;

    /**
     * 是否展示
     */
    @TableField(value = "is_show")
    private Integer isShow = 0;

    /**
     * 签署时间
     */
    @TableField(value = "sign_time")
    private LocalDateTime signTime;

    /**
     * 使用短信多少次
     */
    @TableField(value = "use_sms_num")
    private Integer useSmsNum = 0;

    /**
     * 使用多少分合同
     */
    @TableField(value = "use_contracts_num")
    private Integer useContractsNum = 0;

    /**
     * 使用多少次人脸
     */
    @TableField(value = "use_face_num")
    private Integer useFaceNum = 0;

    /**
     * 版本编号
     */
    @TableField(value = "version")
    @Version
    private Integer version;

    /**
     * 创建时间
     */
    @TableField(value = "create_time")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", update = "now()")
    private LocalDateTime updateTime;

    public String getRandomNo() {
        Calendar calendar = Calendar.getInstance();
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DATE);
        return  "DZHT"
                + calendar.get(Calendar.YEAR)
                + (month >= 10 ? String.valueOf(month) : "0" + month)
                + (day >= 10 ? String.valueOf(day) : "0" + day)
                + calendar.get(Calendar.HOUR_OF_DAY)
                + calendar.get(Calendar.MINUTE)
                + calendar.get(Calendar.SECOND)
                + ((int)((Math.random()*9+1)*10000000));
    }

    @AllArgsConstructor
    @Getter
    public enum Enums {

        TAKE_PET_CONTRACT,
        USER_KNOW_CONTRACT,
        RESERVE_CONTRACT,
        BUY_CONTRACT,

        SIGN,

        INIT,
        SIGN_ING,
        SUCCESS,
        FAIL,
        ABANDON

    }

    public static final Map<String, String> ENUM_MAP = new HashMap<>();

    static {
        ENUM_MAP.put(UserContract.Enums.SIGN.name(), "在线签约");
        ENUM_MAP.put(UserContract.Enums.TAKE_PET_CONTRACT.name(), "领猫合同");
        ENUM_MAP.put(UserContract.Enums.USER_KNOW_CONTRACT.name(), "用户须知合同");
        ENUM_MAP.put(UserContract.Enums.RESERVE_CONTRACT.name(), "预定合同");
        ENUM_MAP.put(UserContract.Enums.BUY_CONTRACT.name(), "直购合同");

        ENUM_MAP.put(UserContract.Enums.INIT.name(), "待签");
        ENUM_MAP.put(UserContract.Enums.SIGN_ING.name(), "签约中");
        ENUM_MAP.put(UserContract.Enums.SUCCESS.name(), "成功");
        ENUM_MAP.put(UserContract.Enums.FAIL.name(), "失败");
        ENUM_MAP.put(UserContract.Enums.ABANDON.name(), "废弃");

    }

}
